import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * @ClassName Demo03_OutputStreamWriter
 * @Description 指定编码写出
 * @Author Li
 * @Date 2022/8/12 9:53
 * @ModifyDate 2022/8/12 9:53
 * @Version 1.0
 */
public class Demo03_OutputStreamWriter {
    public static void main(String[] args) throws IOException {
        // 定义输出文件路径
        String filename1 = "src/part10/ch02_TransformStream/out1.txt";
        String filename2 = "src/part10/ch02_TransformStream/out2.txt";
        // 创建流对象，默认UTF-8编码
        OutputStreamWriter osw1 = new OutputStreamWriter(new FileOutputStream(filename1));
        // 写出数据
        osw1.write("你好");
        osw1.close();

        // 创建流对象，指定GBK编码
        OutputStreamWriter osw2 = new OutputStreamWriter(new FileOutputStream(filename2), "GBK");
        // 写出数据
        osw2.write("你好");
        osw2.close();
    }
}
